//
//  UpdaterManager.m
//  TestGameEngine
//
//  Created by Louis CHU on 21/03/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "UpdaterManager.h"
static UpdaterManager * sSharedUpdaterManager;

@interface UpdaterManager ()
@property (nonatomic, strong) NSMutableArray * updatedObjects;
@end

@implementation UpdaterManager
@synthesize updatedObjects;
+ (UpdaterManager *) sharedUpdaterManager
{
    if (!sSharedUpdaterManager) {
        sSharedUpdaterManager = [UpdaterManager new];
    }
    return sSharedUpdaterManager;
}
- (void) addUpdatedObject: (id<IUpdater>) updatedObject_
{
    if (![self.updatedObjects containsObject:updatedObject_]) {
        [self.updatedObjects addObject:updatedObject_];
    }
}
- (void) removeUpdateedObject: (id<IUpdater>) updatedObject_
{
    if ([self.updatedObjects containsObject:updatedObject_]) {
        [self.updatedObjects removeObject:updatedObject_];
    }
}
- (void) update: (float) elapsedTime
{
    for(id<IUpdater> updatedObject in self.updatedObjects)
    {
        [updatedObject update:elapsedTime];
    }
}

- (NSMutableArray *) updatedObjects
{
    if (!updatedObjects) {
        updatedObjects = [NSMutableArray array];
    }
    return updatedObjects;
}
@end
